#include "qsearchtermsfactory.h"

QSearchTermsFactory::QSearchTermsFactory()
{
}

QSearchTermsFactory::~QSearchTermsFactory()
{
}

QList<QSearchTerms*> QSearchTermsFactory::fromPart(QObjectPool<QSearchTerms>* pool,QEXPPart* part)
{

   QList<QSearchTerms*> terms;
	QList<QSearchTerms*> init;
	quint8 load=0;
	if(part && pool)
   {

		init << pool->acquire() << pool->acquire() << pool->acquire() << pool->acquire() << pool->acquire();
		init[0]->set(BDD_PLP,part->get(EXP_CODE_PLP),S_CONTAINS,100);
      if(part->get(EXP_DESIGNATOR) == EXP_RESISTOR_DESIGNATOR)
      {
			load = 5;
			init[1]->set(PART_RESISTOR_VALUE,part->get(EXP_REAL_VALUE),S_EQUAL,60);
			init[2]->set(PART_TOLERANCE,part->get(EXP_TOLERANCE),S_LESSER_THAN_OR_EQUAL ,20);
			init[3]->set(PART_PACKAGE,part->get(EXP_PACKAGE),S_EQUAL ,20);
			init[4]->set(PART_POWER,part->get(EXP_POWER),S_GREATER_THAN_OR_EQUAL ,20);
      }
      else if(part->get(EXP_DESIGNATOR) == EXP_CAPACITOR_DESIGNATOR)
      {
			load = 5;
			init[1]->set(PART_CAPACITOR_VALUE,part->get(EXP_REAL_VALUE),S_EQUAL,60);
			init[2]->set(PART_TOLERANCE,part->get(EXP_TOLERANCE),S_LESSER_THAN_OR_EQUAL ,20);
			init[3]->set(PART_PACKAGE,part->get(EXP_PACKAGE),S_EQUAL ,20);
			init[4]->set(PART_VOLTAGE,part->get(EXP_VOLTAGE),S_GREATER_THAN_OR_EQUAL ,20);
      }
      else if(part->get(EXP_DESIGNATOR) == EXP_SELF_DESIGNATOR)
      {
			load = 5;
			init[1]->set(PART_SELF_VALUE,part->get(EXP_REAL_VALUE),S_EQUAL,60);
			init[2]->set(PART_TOLERANCE,part->get(EXP_TOLERANCE),S_LESSER_THAN_OR_EQUAL ,20);
			init[3]->set(PART_PACKAGE,part->get(EXP_PACKAGE),S_EQUAL ,20);
			init[4]->set(PART_CURRENT,part->get(EXP_CURRENT),S_GREATER_THAN_OR_EQUAL ,20);
      }
      else
      {
			load = 3;
			init[1]->set(BDD_FAB,part->get(EXP_MANUFACTURER),S_EQUAL,20);
			init[2]->set(BDD_REF_FAB,part->get(EXP_MANUFACTURER),S_CONTAINS,50);
      }
		
		for(int i=0;i<5;i++)
		{
			if(i<load)
				terms << init[i];
			else
				pool->release(init[i]);
		}
   }
   return terms;
}


QString QSearchTermsFactory::normalize(QString text)
{
   if(text == EXP_UNKNOWN)
      return "";
   return text;
}